package com.itheima.pay.controller;

import com.github.wxpay.sdk.WXPay;
import com.itheima.pay.config.WXPayConfigCustom;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Version: V1.0
 */
@Controller
@RequestMapping("trading")
public class WxController {


    /**
     * 下单操作
     * @param code
     * @return
     * @throws Exception
     */
    @GetMapping("orderquery/{code}")
    public Map unifiedOrder(@PathVariable String code) throws Exception {
        WXPayConfigCustom config = new WXPayConfigCustom();
        WXPay wxpay = new WXPay(config);

        Map<String, String> data = new HashMap<String, String>();
        data.put("out_trade_no", code);

        try {
            Map<String, String> resp = wxpay.orderQuery(data);
            System.out.println("支付结果："+resp);

            return resp;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

}
